package com.aotao.springboot.controller;

import com.aotao.springboot.domain.Article;
import com.aotao.springboot.service.ArticleService;
import com.aotao.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/admin")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public String login(String username, String password, HttpSession session,Model model){
        System.out.println(username+":"+password);
        System.out.println(userService.findUser());
        if (username.equals("aotao") && password.equals("123456")){
            session.setAttribute("username",username);
            return "redirect:/admin/toIndex";
        }else {
            model.addAttribute("err","用户名或账号错误");
            return "forward:/admin/toLogin";
        }
    }

    //注销
    @RequestMapping("/logout")
    public String logout(HttpSession session){
        session.removeAttribute("username");
        return "redirect:/admin/toIndex";
    }


}
